import $service from '../../../../service'
const app = getApp();
let current = 1;
Page({
  data: {
    logList: [],
    totalPage: ''
  },
  onLoad(e) {
    this.userId = e.userId
    this.userSource = e.userSource
    current = 1;
    this.chatRecordLog();
  },
  onReachBottom() {
    if (current == this.data.totalPage) {
      $service.showToast('已经到底啦')
    } else {
      current++
      this.chatRecordLog()
    }

  },
  chatRecordLog() {
    let params = {
      "current": current,
      "patientId": this.userId,
      "size": 10,
      "userSource": this.userSource
    }
    app.http.chatRecordLog(params).then(res => {
      if (current <= res.data.pages) {
        this.data.logList = this.data.logList.concat(res.data.list)
      }
      this.data.logList.forEach((item) => {
        if (item.msgText.indexOf('jpg') > 0) {
          item.imageId = 1
        } else {
          item.imageId = 0
        }
      })
      this.setData({
        logList: this.data.logList,
        totalPage: res.data.pages
      })
    }).catch(err => {
      $service.showToast(err.msg)
    })
  }
})